import {Fragment, useEffect} from 'react'
import {Header} from './layout/header'
import {Body} from './layout/body'
import React from 'react'
import {useState} from 'react'
import {BrowserRouter, Route, Routes, useNavigate} from 'react-router-dom'
import {Test} from './components/test'
import {DateLines} from './views/date'
import {Navigate} from 'react-router-dom'
import {Home} from './views/home'
import {BlogEdit, BlogInfo} from './views/blog'
import {Login} from "./views/Login";
//富文本编辑器
import "react-quill/dist/quill.snow.css";
import {ConfigProvider} from "antd";

export default function App() {
    const [size] = useState('large')
    //首页
    const HomePage = <Home/>
    //博客页面
    const MainPage = <Body/>
    //测试页面
    const TestPage = <Test/>
    //登录页面
    const LoginPage = <Login/>

    //date页面
    const DatePage = <DateLines/>
    //重定向
    const RedirectHome = <Navigate to="/home"/>
    const BlogEditPage = <BlogEdit/>

    //token
    const token = localStorage.getItem('token') || sessionStorage.getItem('token')
    return (
        <Fragment>
            <ConfigProvider theme={{
                token: {
                    // Seed Token，影响范围大
                    colorPrimary: '#1c1c1c',
                    borderRadius: 2,

                    // 派生变量，影响范围小
                    colorBgContainer: '#ffffff',
                },
            }}>
                <BrowserRouter>
                    {/* Routes放哪里 哪里就变化 */}
                    <Header/>
                    {token === null || token === '' || token === undefined ? LoginPage : <Routes>
                        <Route path="/" element={RedirectHome}/>
                        <Route path="/blog" element={<BlogInfo/>}/>
                        <Route path="/home" element={HomePage}/>
                        <Route path="/blog/content/:blog_id" element={MainPage}/>
                        <Route path="/blog_edit" element={BlogEditPage}/>
                        <Route path="/test" element={TestPage}/>
                        <Route path="/login" element={LoginPage}/>
                        <Route path="/date" element={DatePage}/>
                    </Routes>}
                </BrowserRouter>
            </ConfigProvider>
        </Fragment>
    )
}
